package consumer6;

import java.util.concurrent.BlockingQueue;

public class Producer implements Runnable {

	int num = 0;

	private final BlockingQueue<Integer> q;

	public Producer(BlockingQueue<Integer> q) {
		this.q = q;
	}

	@Override
	public void run() {
		try {
			while (true) {
				q.put(produce());
				Thread.sleep(500);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	Integer produce() {
		return ++num;
	}
}
